<?php

class mainItems{

    var $article;
    var $page;
    var $title = null;
    var $thumb = null;
    var $summary = null;

    function set_id($new_id){
        $this->id = $new_id;
        return $this->id;
    }

    function set_page($new_page){
        $this->pageid = $new_page;
        return $this->pageid;
    }

    function get_mainItems(){
        $connect = new mysqli(DB_HOST,DB_USER,DB_PASS,DB_NAME);
        if($result = $connect->query("SELECT SUBSTRING(summary, 1, 200 )AS shortSummary, summary, id, time, title, thumb FROM ".$prefix."posts WHERE headline = '1' AND draft = '0' ORDER BY time DESC LIMIT 2")) {
            while($row = $result->fetch_object()){
                if($row->shortSummary < $row->summary){
                    $shortSummary = $row->shortSummary.'...';
                }
                else{
                    $shortSummary = $row->shortSummary;
                }
                $this->mainItem[] = array(
                "id" => $row->id,
                "title" => $row->title,
                "thumb" => $row->thumb,
                "summary" => $shortSummary
                );
            }
            return $this->mainItem;
            $result->close();
        } else {
            return $connect->error;
        }
        $connect->close();
    }
}

?>
